package com.utils;

import com.exception.LoginTimeOutException;
import com.model.SysUser;
import com.vo.LoginData;
import org.springframework.util.ObjectUtils;

/**
 * @Author: chihaojie
 * @Date: 2019/6/22 10:39
 * @Version 1.0
 * @Note
 */
public class CurrentLoginUserAgent {

    public static   Long  getBusinessId(){
        LoginData currentUser = SessionUtil.getCurrentUser();
        if(ObjectUtils.isEmpty(currentUser)){
            throw  new LoginTimeOutException("登录超时,请重新登录");
        }
        //判断用户类型
        if(currentUser.getUserType().equals(1)){
            return currentUser.getUserId();
//            return null;
        }else if(currentUser.getUserType().equals(2)){
            return  currentUser.getUserId();
        }else return currentUser.getLeaderId();
    }

    public static SysUser getUser(){
        LoginData currentUser = SessionUtil.getCurrentUser();
        SysUser user=new SysUser();
        user.setId(currentUser.getUserId());
        user.setUserType(currentUser.getUserType());
        user.setUserName(currentUser.getUsername());
        user.setLeaderId(currentUser.getLeaderId());
        return  user;
    }
}
